package com.mumu.studykotlin.gra

/**
 *edie create on 2019/7/24
 *
 */
class ArrayDemo {

    fun toArr() {
        //[1,2,3]
        val a = arrayOf(1, 2, 3)
        //[0,2,4]
        val b = Array(3) { i -> (i * 2) }
        val chars = Array(3) { i: Int -> i * 4 }

        //读取数组内容
        println(a[0])    // 输出结果：1
        println(b[1])    // 输出结果：2
        println(chars.get(1))


        for (aa: Int in a) print(aa)
        println()
        for (aa in 0 until a.size) print(a[aa])
    }

    fun doFor() {
        loop@ for (i in 0..100) {
            for (j in 0..100) {
                println("i是$i,j是$j")
                if (i == 2 && j == 5) break@loop
            }
        }
    }


    class Person {

        var lastName: String = "zhang"
            get() = field.toUpperCase()   // 将变量赋值后转换为大写

        var no: Int = 100
            set(value) {
                field = if (value < 10) {       // 如果传入的值小于 10 返回该值
                    value
                } else {
                    -1         // 如果传入的值大于等于 10 返回 -1
                }
            }

        var heiht: Float = 145.4f
            private set
    }

//    class Person constructor(firstName: String) {
//        init {
//            println("FirstName is $firstName")
//        }
//    }

   inner class People(name: String) {
        init {
            println("FirstName is $name")
        }
    }
}